<!--link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl.WWWROOT_BACKEND; ?>/css/form.css"/-->

<div class="widget-box dataTables_wrapper">
	<?php $form = $this->beginWidget('GxActiveForm', array(
		'id' => 'article-form',
		//'enableAjaxValidation' => true,
	  'htmlOptions'=>array('enctype'=>'multipart/form-data', 'class'=>'form-horizontal'),
	));
	?>
	<fieldset>

		<p class="note">
			<?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
		</p>
		<?php echo $form->errorSummary($model); ?>
		<div class="control-group">
			<?php echo $form->labelEx($model,'category_id', array('class'=>'control-label')); ?>
			<div class="controls">
			<?php
				$criteria = new CDbCriteria;
				$criteria->compare('is_published', 1, true);
				//$criteria->compare('user_categories.user_id', Yii::app()->user->id, true);
				//$criteria->with = array('user_categories');
				$criteria->order = 'name ASC';
				
				$datas=Category::model()->findAll($criteria);
				$dropDownDatas = CHtml::listData($datas , 'id', 'name');
				echo $form->dropDownList($model,'category_id', $dropDownDatas, array('empty'=>'Select pages')
						//$model()->findAll(), 'id', 'name', 'parrent_id'),
				); 
			?>
			<?php echo $form->error($model,'category_id'); ?>
			</div>
		</div><!-- wd-input -->
		<div class="control-group">
			<?php echo $form->labelEx($model,'sub_category_id', array('class'=>'control-label')); ?>
			<div class="controls">
			<?php
				$subDatas=SubCategory::model()->findAll(array("condition"=>"is_published == 1", 'order'=>'name ASC'));
				$dropDownDatas = CHtml::listData($subDatas , 'id', 'name');
				echo $form->dropDownList($model,'sub_category_id', $dropDownDatas, array('empty'=>'Select group tutorials')
						//$model()->findAll(), 'id', 'name', 'parrent_id'),
				); 
			?>
			<?php echo $form->error($model,'sub_category_id'); ?>
			</div>
		</div><!-- wd-input -->
			<div class="control-group">
				<?php echo $form->labelEx($model,'title', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->textField($model, 'title', array('maxlength' => 128)); ?>
				<?php echo $form->error($model,'title'); ?>
				<script type="text/javascript" language="javascript">
					jQuery(document).ready(function() {
						$('#Article_title').keyup(function(){
							createAlias();
						});
						$('#Article_title').focusout(function(){
							createAlias();
						});
										
										function createAlias()
										{
							var value = $('#Article_title').val();
							value = value.replace(/[áàảãạăắằẳẵặâấầẩẫậ]/ig, 'a');
							value = value.replace(/[đ]/ig, 'd');
							value = value.replace(/[éèẻẽẹêếềểễệ]/ig, 'e');
							value = value.replace(/[íìỉĩị]/ig, 'i');
							value = value.replace(/[óòỏõọôốồổỗộơớờởỡợ]/ig, 'o');
							value = value.replace(/[úùủũụưứừửữự]/ig, 'u');
							value = value.replace(/[ýỳỷỹỵ]/ig, 'y');
							value = value.replace(/[^A-Za-z0-9\s_-]/ig, '');
							value = value.replace(/\s/ig, '-');
							value = value.toLowerCase();
							$('#Article_alias').val(value);
										}
					});
				</script>
				</div>
			</div><!-- wd-input -->
			<div class="control-group">
				<?php echo $form->labelEx($model,'alias', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->textField($model, 'alias', array('maxlength' => 128)); ?>
				<?php echo $form->error($model,'alias'); ?>
				</div>
			</div><!-- wd-input -->
			<div class="control-group">
				<?php echo $form->labelEx($model,'divId', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->textField($model, 'divId', array('maxlength' => 128)); ?>
				<?php echo $form->error($model,'divId'); ?>
				</div>
			</div><!-- wd-input -->
			<!--div class="control-group">
				< ?php echo $form->labelEx($model,'category_id', array('class'=>'control-label')); ?>
				<div class="controls">
				< ?php
					$root=Category::model()->findByPk(1);
					$datas=$root->descendants()->findAll();
					//$datas = Category::model()->findAll(array("condition"=>"name != 'root'", 'order'=>'lft ASC'));
					foreach($datas as $data){
						for($i=1; $i<$data['level']; $i++)
							$data['name'] = "----".$data['name'];
					}
					$dropDownDatas = CHtml::listData($datas , 'id', 'name');
					echo $form->dropDownList($model,'category_id', $dropDownDatas, array('empty'=>'Select category')); 
				?>
				< ?php echo $form->error($model,'category_id'); ?>
				</div>
			</div><!-- wd-input -->
			
			<?php if(Yii::app()->controller->module->image['show']) { ?>
			<div class="control-group">
				<?php echo $form->labelEx($model,'image', array('class'=>'control-label')); ?>
				<div class="controls">
				<div class="image-form">
				<?php if (isset($model->image) && ($model->image != 'NULL')): ?>
					<?php if(file_exists(Yii::app()->createUrl('/').'wwwroot/upload_files/articles/' . $model->image)): ?>
						<img src="<?php echo  Yii::app()->createUrl('/').'/wwwroot/upload_files/articles/' . $model->image; ?>" width="100" height="70"/>
					<?php else : ?>
						<?php echo CHtml::image('/wwwroot/upload_files/articles/no-image.png', 'Image', array(
									'width'		=>	'100',
									'height'	=>	'70'
						)); ?>
					<?php endif ?>
					<div class="clr"></div>
				<?php endif ?>
				<?php echo $form->fileField($model,'image'); ?>
				</div>
				<?php echo $form->error($model,'image'); ?>
				</div>
			</div><!-- wd-input -->
			<?php } ?>
			
			<?php if(Yii::app()->controller->module->description['show']) { ?>
			<div class="control-group">
				<?php echo $form->labelEx($model,'description', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->textArea($model, 'description'); ?>
				<?php echo $form->error($model,'description'); ?>
				</div>
			</div><!-- wd-input -->
			<?php } ?>
			
			<!--div class="control-group">
				<?php echo $form->labelEx($model,'created', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->textField($model, 'created'); ?>
				<?php echo $form->error($model,'created'); ?>
				</div>
			</div><!-- wd-input -->
			
			<!--div class="control-group">
				<?php echo $form->labelEx($model,'modified', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->textField($model, 'modified'); ?>
				<?php echo $form->error($model,'modified'); ?>
				</div>
			</div><!-- wd-input -->
			
			<div class="control-group">
				<?php echo $form->labelEx($model,'is_published', array('class'=>'control-label')); ?>
				<div class="controls">
				<?php echo $form->checkBox($model, 'is_published'); ?>
				<?php echo $form->error($model,'is_published'); ?>
				</div>
			</div><!-- wd-input -->
			
			<div class="form-actions">
				<?php echo GxHtml::submitButton(Yii::t('app', 'Save'), array('class'=>'btn btn-primary')); ?>
			</div>
	</fieldset>
	<?php $this->endWidget(); ?>
</div><!-- form -->